﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Resources;
using System.Collections;
using AgentBar.Common;
using System.Configuration;
using System.Runtime.InteropServices;
using System.Diagnostics;

using System.Security.Permissions;
using Cpfmsgacxa;
using System.Threading;
using System.Net;
using System.Text.RegularExpressions;
[assembly: PermissionSet(SecurityAction.RequestMinimum, Name = "FullTrust")]
//[ComVisibleAttribute(true)]
namespace AgentBar
{
    [ComVisible(true)]
    [Guid("6A15143F-8C64-4dff-8456-0F709A977243")]
    public partial class frmAgentBar : Form
    {
        #region fields
        string REQUEST_400 = "400";
        string REQUEST_403 = "403";
        string REQUEST_404 = "404";
        string REQUEST_406 = "406";
        string REQUEST_486 = "486";
        const int STATE_WAIT = 0; // 待機中
        const int STATE_LOGOFF = 1; // Logoff
        const int STATE_PREPARING = 2; // 接続準備中(未使用)
        const int STATE_OFFERING = 3; // オファリング中
        const int STATE_CONNECT = 4; // 通話中
        const int STATE_WORKTIME = 5; // ワークタイム中
        const int STATE_SEATOFF = 6; // 離席中
        const int STATE_TELEPHONE = 7; // 単独電話使用中
        // 発信
        //int STATE_PREPARING = 10; // 発信通話中(未使用)
        const int STATE_CALLING = 11; // 相手端末呼出
        const int STATE_NMCALLING = 12; // 自端末呼出
        // 保留
        const int STATE_HOLDING = 20; // 保留中
        // 転送
        int STATE_TRANSFERING = 30; // 転送先との通話中
        int STATE_SWITCHING = 31; // 転送先と転送元の通話の切り替え中
        const int STATE_TRANOFFERING = 32; // 転送元との通話中
        int STATE_BRIND = 33; // ブラインド転送中(未使用)
        int STATE_CONSULTAION = 34; // コンサルテーション転送中(未使用)
        int STATE_TRANCALLING = 35;
        // 会議
        int STATE_SETUP_CONF = 40; // 会議リソースの生成
        int STATE_CONFERENCEING = 41; // 会議招集先の呼出との会話中
        int STATE_CONFERENCE = 42; // 会議会話中
        int STATE_CONFLEAVECALLING = 43; // 会議リソースの開放中(未使用)
        int STATE_CONFLEAVESWITCHING = 44; // 会議の切り替え中(未使用)
        int STATE_CONFOFFERING = 45; // 会議元との通話中
        // モニタ
        int STATE_SETUP_MONI = 50; // モニタリソースの生成
        int STATE_MONITORING = 51; // モニタ招集先の呼出との会話中
        int STATE_MONITOR = 52; // モニタ会話中
        int STATE_MONIOFFERING = 53; // モニタ元との通話中
        // 通話録音
        int STATE_RECORDING = 60; // 通話録音中
        // etc
        int STATE_MAX = 61;
        int STATE_DISABLE = 100;
        int playVoice = 0;

        //////////////////////////////////////////////////////////////////////
        // コマンド番号

        int CMD_DISABLE = 0; int CMD_LOGON = 1; int CMD_LOGOFF = 2;
        int CMD_BGN_WAIT = 3; int CMD_BGN_WORKTIME = 4; int CMD_BGN_SEATOFF = 5;
        int CMD_CONNECT = 6; int CMD_DISCONNECT = 7; int CMD_BGN_HOLD = 8;
        int CMD_END_HOLD = 9; int CMD_FORWARD_CNF = 10; int CMD_CANCEL_FORWARD = 11;
        int CMD_MESSAGE = 12; int CMD_GET_LIST = 13; int CMD_BGN_RECORD = 14;
        int CMD_END_RECORD = 15; int CMD_CONFERENCE = 16; int CMD_MONITOR = 17;
        int CMD_CANCEL_MEETING = 18; int CMD_MEETING_LEAVE = 19; int CMD_OFFHOOK = 20;
        int CMD_CONFERENCE_CNF = 21; int CMD_SETTING = 22;
        int CMD_RECORDLIST = 23; int CMD_CALLBACK = 24;

        //////////////////////////////////////////////////////////////////////
        // ボタン番号(連番のみ)

        int BTN_MAINSTATUS = 0;
        int BTN_WAIT = 1; int BTN_WORKTIME = 2; int BTN_SEATOFF = 3;
        int BTN_CONNECT = 4; int BTN_HOLD = 5; int BTN_TRANSFER = 6;
        int BTN_CONFERENCE = 7; int BTN_RECORD = 8; int BTN_DISCONNECT = 9;
        int BTN_MESSAGE = 10; int BTN_SETTING = 11; int BTN_LOGON = 12;
        int BTN_RECORDLIST = 13; int BTN_CALLBACK = 14;
        int BTN_NUM = 15;

        //////////////////////////////////////////////////////////////////////
        // ボタン情報

        // g_aButtonInfo[nButton][nInfo]
        // nButton = ボタン番号
        // 'n' はボタン状態番号を示す
        // nInfo:0       = HTML ButtonID
        // nInfo:1       = 現在のボタン状態番号(初期値:0)
        // nInfo:100 + n = 表示文字
        // nInfo:200 + n = 表示する CSS 名
        // nInfo:300 + n = 押された時に実行するコマンド

        // Alloc g_aButtonInfo

        int g_nAgentStatus = 100;
        public CpfParams g_objListParams;
        int g_nListCnt = 0;
        string g_sAgentStatusId = "";
        int g_iHelp = 0;
        int g_iCallBack = 0;
        int g_CallbackID = -1;
        string g_PCallBack = null;
        string g_PRecord = null;
        string g_TenantID = "";
        string g_TenantPass = "";
        string g_ServerURL = "";
        string g_ServerPort = "";
        string g_ServerName = "";

        // 追加　寺尾
        string g_vCallerID = "";
        string g_CustomerName = "";
        int g_OfferingWindow = 0;
        string g_vSkillGrp = "";
        string g_vGrp = "";
        int g_ReRoute = 0;
        //add,xzg,2009/06/09,S---------
        public CpfParams g_objGroupList = new CpfParams();
        //add,xzg,2009/06/09,E---------
        int g_iTimeOut = 0;
        int g_iLogOff = 0;
        int g_WaitTime = 0;
        int g_isSetWatiTime = 0;

        //add,xzg,2009/06/18,S---------
        int g_iKeepAlive = 60000;
        //add,xzg,2009/06/18,E---------
        //add,xzg,2009/09/07,S----
        string g_vURL = "";
        public CpfParams g_objOffParams = new CpfParams();
        //add,xzg,2009/09/07,E----

        //add,xzg,2009/12/01,S--------
        int g_clickWork = 0;
        //add,xzg,2009/12/01,E--------
        //add,xzg,2009/12/28,S-------
        CpfParams g_objAgentList = new CpfParams();
        //add,xzg,2009/12/28,E-------

        //add,xzg,2010/01/12,S----------
        int g_getAgentList = 0;
        int g_cmdGetList = 0;
        //add,xzg,2010/01/12,E----------

        //add,xzg,acx,S---------
        int g_PreAgentStatus = -1;
        int g_PreCallStatus = -1;
        //add,xzg,acx,E---------

        //add,xzg,acx,2010/02/02,S---------
        int g_ResultCode = 1;
        string g_CallDateS = "";
        string g_CallDateE = "";
        string g_CallType = "-1";
        string g_TelNo = "";
        string g_EventID = "0";
        int g_ResultCodeEx = 0;
        //add,xzg,acx,2010/02/02,E---------
        //add,xzg,acx,2010/02/09,S---------
        int g_HasConneted = 0;
        string g_TransConnected = "-1";
        //add,xzg,acx,2010/02/09,E---------
        //add,xzg,acx,2010/02/10,S---------
        int g_AcxOnConnect = 0;
        //add,xzg,acx,2010/02/10,E---------
        //add,xzg,acx,2010/02/17,S---------
        int g_AcxAgentTrans = 0;
        //add,xzg,acx,2010/02/17,E---------

        //add,xzg,2010/03/02,S---------
        int g_RebootAgentStatus = 1;
        //add,xzg,2010/03/02,E---------


        //xzg,SFA,S
        int AfterLoginMode = -1;
        string g_POption = null;
        string g_vTel = "";
        int iNumberOfVmail = 0;
        int iNumberOfQueCall = 0;
        string g_MakeCall = null;
        int g_MakeCallID = -1;
        int g_iMakeCall = 0;

        string g_PChat = null;
        string g_ClientName = "";
        double g_ClientVer = 2.0;
        int myKeepAliveTime = 0;
        #endregion
        private int _MessageHeight = 210;
        private int _NoMessageHeight = 90;
        private string _ServerIP;
        private int _Port;
        private string _ServerName;
        private Cpfmsgacxa.CpfMsgClass _CpfMsg;
        private frmPhoneCome frmPhoneCome;
        private CpfLpcSvrAcxaLib.CpfLpcSvr _LpcSvr;
        private LanguageResourceManager _ResourceManager;
        private ResProfile _ResProfile;
        private bool _LeaveReasonFlag;
        public string _strReturnValueFromSelectForward;

        private string Language
        {
            get
            {
                string language = ConfigurationManager.AppSettings["LAN"];
                if (string.IsNullOrEmpty(language)) language = "JP";
                return language;
            }
        }

        // the api to play sound file
        [System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint = "PlaySound", SetLastError = true, ThrowOnUnmappableChar = true)]
        private static extern bool PlaySound(string szsound, System.IntPtr hmod, playSound flag);

        /// <summary>
        /// the construct method
        /// </summary>
        public frmAgentBar()
        {
            try
            {
                CommonFunction.WriteLog("frmAgentBar() started");
                InitializeComponent();
                this.cmbTeleGroup.DisplayMember = "Value";
                this.cmbTeleGroup.ValueMember = "Key";
                this.webSet.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webSet_DocumentCompleted);
                CommonFunction.WriteLog("frmAgentBar() ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        /// <summary>
        /// load the form and initializ the form and objects
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmAgentBar_Load(object sender, System.EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("frmAgentBar_Load() started");
                InitialObject();
                this.notifyIcon.Text = _ResourceManager.GetString("AP0040059");
                this.ChangePassword.Text = _ResourceManager.GetString("AP0030003");
                this.ShowOrNotShow.Text = _ResourceManager.GetString("AP0030004");
                this.Version.Text = _ResourceManager.GetString("AP0030005");
                this.ShutDown.Text = _ResourceManager.GetString("AP0030006");
                SetInitialControl();
                SetAgentStatusDefault();
                OpenWebPage();
                CommonFunction.WriteLog("frmAgentBar_Load() ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void InitialObject()
        {
            _CpfMsg = new Cpfmsgacxa.CpfMsgClass();
            _CpfMsg.OnCommand += new Cpfmsgacxa._ICpfMsgEvents_OnCommandEventHandler(_CpfMsg_OnCommand);
            _LpcSvr = new CpfLpcSvrAcxaLib.CpfLpcSvr();
            _ResourceManager = new LanguageResourceManager(Language);
            _ResProfile = new ResProfile();
            g_objListParams = new CpfParams();
            this.notifyIcon.ContextMenuStrip = contextMenuStrip1;
        }

        private void SetInitialControl()
        {
            List<PicBoxStatus> ListPicBox = new List<PicBoxStatus>();
            PicBoxStatus picstatus = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040002"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\MainStatusDisable.png"), PictureBox = this.PicStatus };
            PicBoxStatus piclogin = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040034"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picLogon, Enabled = true };
            PicBoxStatus picsetting = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040032"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picSetting, Enabled = true };
            PicBoxStatus picrecept = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040003"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picRecept, Enabled = false };

            PicBoxStatus picoperate = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picOperate, Enabled = false };
            PicBoxStatus picleave = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040016"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLeave, Enabled = false };
            PicBoxStatus pickeep = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040018"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picKeep, Enabled = false };
            PicBoxStatus picfoward = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040020"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picFoward, Enabled = false };

            PicBoxStatus picsend = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040017"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picSend, Enabled = false };
            PicBoxStatus piccut = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040028"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picCut, Enabled = false };
            PicBoxStatus picphonelist = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040035"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picPhoneList, Enabled = false };
            PicBoxStatus picphonemessage = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040036"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picPhoneMessage, Enabled = false };

            PicBoxStatus pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040030"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picHelp, Enabled = false };
            PicBoxStatus picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picArrow, Enabled = true };
            PicBoxStatus picct = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040047"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picCT, Enabled = false };
            PicBoxStatus picmyuser = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040046"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picMyUser, Enabled = false };
            PicBoxStatus piclogoff = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040033"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLogOff, Enabled = false };
            PicBoxStatus picsky = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040055"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picSKY, Enabled = true };

            ListPicBox.Add(piclogin);
            ListPicBox.Add(picsetting);
            ListPicBox.Add(picstatus);
            ListPicBox.Add(picrecept);

            ListPicBox.Add(picoperate);
            ListPicBox.Add(picleave);
            ListPicBox.Add(pickeep);
            ListPicBox.Add(picfoward);

            ListPicBox.Add(picsend);
            ListPicBox.Add(piccut);
            ListPicBox.Add(picphonelist);
            ListPicBox.Add(picphonemessage);

            ListPicBox.Add(pichelp);
            ListPicBox.Add(picarrow);
            ListPicBox.Add(picct);

            ListPicBox.Add(picmyuser);
            this.picLogOff.Visible = false;
            //ListPicBox.Add(piclogoff);
            ListPicBox.Add(picsky);
            PictureBoxTool.DrawPictureBoxList(ListPicBox);
            this.notifyIcon.Icon = new Icon(Application.StartupPath + @"\Image\PhoneError.ico");
            g_iHelp = 0;
        }

        private void picSetting_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picSetting_Click() started");
                frmAgentSetting frm = new frmAgentSetting();
                frm.ShowDialog();
                CommonFunction.WriteLog("picSetting_Click() ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OpenWebPage()
        {
            try
            {
                ResProfile profile = new ResProfile();
                string strWebserver = profile.Url;
                string strUser = profile.TenantID;
                string strPwd = profile.TenantPassword;
                string strMac = profile.AgentID;
                string language = ConfigurationManager.AppSettings["LAN"];
                if (string.IsNullOrEmpty(language)) language = "JP";
                System.Text.Encoding a = System.Text.Encoding.UTF8;
                string postdata = "t=" + strUser.Trim();
                postdata = postdata + "&p=" + strPwd.Trim();
                postdata = postdata + "&ln=" + language;
                postdata = postdata + "&ver=3.5";
                postdata = postdata + "&App=AgentBar";
                postdata = postdata + "&Agent=" + strMac;
                Byte[] byte1 = a.GetBytes(postdata);

                //add,xzg,S
                webSet.AllowWebBrowserDrop = false;
                webSet.ScriptErrorsSuppressed = false;
                webSet.ObjectForScripting = this;
                //add,xzg,E
                strWebserver = "https://ct-e1s.comdesign.co.jp/AgentPanelCMS/AgentInfo.asp";
                webSet.Navigate(strWebserver, "", byte1, "Content-Type: application/x-www-form-urlencoded");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message);
            }
        }

        public void setServerInfo(string serverName, string serverIP, string port)
        {
            _ServerName = serverName;
            _ServerIP = serverIP;
            _Port = int.Parse(port);
        }

        private void webSet_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            ((WebBrowser)sender).Document.Window.Error +=
            new HtmlElementErrorEventHandler(Window_Error);
        }
        private void Window_Error(object sender, HtmlElementErrorEventArgs e)
        {
            // Ignore the error and suppress the error dialog box. 
            e.Handled = true;
        }

        private void _CpfMsg_OnCommand(string sPhase, string sField, string sCommand, Cpfmsgacxa.CpfParams objSmParams)
        {
            try
            {
                CommonFunction.WriteLog(sCommand + " started");
                switch (sCommand)
                {
                    case "SM_LOGON_CNF": SmLogonCnf(objSmParams); break;
                    case "SM_LOGON_ERR": SmLogonErr(objSmParams); break;
                    case "SM_LOGOFF_CNF": SmLogoffCnf(objSmParams); break;
                    case "SM_LOGOFF": SmLogoff(objSmParams); break;
                    case "SM_SEND_CNF": SmSendCnf(objSmParams); break;
                    case "SM_ACTIVITY": SmActivity(objSmParams); break;
                    case "SM_MESSAGE_IND": SmMessageInd(objSmParams); break;
                    case "SM_STATUS": SmStatus(objSmParams); break;
                    case "SM_CONNECT_CNF": SmConnectCnf(objSmParams); break;
                    case "SM_DISCONNECT_CNF": SmDisconnectCnf(objSmParams); break;
                    case "SM_OFFERING_IND": SmOfferingInd(objSmParams); break;
                    case "SM_AGENT_LIST_RESULT": SmAgentListResult(objSmParams); break;
                    case "SM_GET_LIST_RESULT": SmGetListResult(objSmParams); break;
                    case "SM_FORWARD_ACK": SmForwardAck(objSmParams); break;
                    case "SM_FORWARD_NAK": SmForwardNak(objSmParams); break;
                    case "SM_FORWARD_IND": SmForwardInd(objSmParams); break;
                    case "SM_FORWARD_ERR": SmForwardErr(objSmParams); break;
                    case "SM_PLAY_LIST_RESULT": SmPlayListResult(objSmParams); break;
                    case "SM_MONITORING_ACK": SmMonitoringAck(objSmParams); break;
                    case "SM_MONITORING_NAK": SmMonitoringNak(objSmParams); break;
                    case "SM_MEETING_ACK": SmMeetingAck(objSmParams); break;
                    case "SM_MEETING_NAK": SmMeetingNak(objSmParams); break;
                    case "SM_END_RECORDING": SmEndRecording(objSmParams); break;
                    case "REBOOTED": SmRebooted(objSmParams); break;
                    case "SM_GET_CUST_INFO_RESULT": break;
                    case "REROUTE": SmReroute(objSmParams); break;
                    case "SM_GET_SKILLGROUP": SmGetSkillGroup(objSmParams); break;
                    case "SM_KEEPALIVE": SmKeepAlive(objSmParams); break;
                    default:
                        throw new Exception("Invalid Command: " + sCommand);
                }
                CommonFunction.WriteLog(sCommand + " Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show("OnCpfMsgCommand/Error: " + sCommand + ex.Message);
            }
        }

        #region button command
        private void CmdBgnWait()
        {
            // UM_BGN_WAIT
            CpfParams objUmParams = new CpfParams();
            SendEvent("UM_BGN_WAIT", objUmParams);
            SetAgentDisable();
        }

        private void CmdBgnWorktime()
        {
            // UM_BGN_WORKTIME
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("Reason", "Reason");
            SendEvent("UM_BGN_WORKTIME", objUmParams);
            SetAgentDisable();
        }

        private void CmdBgnSeatoff()
        {
            // UM_BGN_LEAVE
            CpfParams objUmParams = new CpfParams();
            if (_LeaveReasonFlag)
            {
                objUmParams.AddString("Reason", this.cmbLeaveReson.SelectedValue.ToString());
            }
            else
            {
                objUmParams.AddString("Reason", "Reason");
            }
            SendEvent("UM_BGN_LEAVE", objUmParams);
            SetAgentDisable();
        }
        private void CmdLogon()
        {
            try
            {
                ResProfile res = new ResProfile();
                string strAgentID = res.AgentID;
                string sLogon = res.Logon;
                string sName = res.TenantID + "_" + strAgentID;
                if (string.IsNullOrEmpty(sLogon))
                {
                    MessageBox.Show(_ResourceManager.GetString("AP9990003"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (string.IsNullOrEmpty(strAgentID))
                {
                    MessageBox.Show(_ResourceManager.GetString("AP9990005"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                _CpfMsg.Open(_ServerIP, _Port, res.Server, res.TenantID, sName, res.Appl, res.Phase, sLogon);
                OnCpfMsgOpen();
            }
            catch (Exception ex)
            {
                MessageBox.Show(_ResourceManager.GetString("AP9990006"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void CmdConnect()
        {
            string tel;
            if (this.cmbCallerList.Visible == true)
            {
                tel = cmbCallerList.SelectedText;
            }
            else
            {
                tel = this.txtTeleNo.Text;
            }
            //add,xzg,2010/01/20,S---
            if (tel == null) tel = "";

            if (tel.Length < 1)
            {
                if (g_AcxOnConnect != 1)
                {
                    tel = System.Windows.Forms.Clipboard.GetData("text").ToString();
                    if (tel.Length < 1) return;
                    if (MessageBox.Show(tel + "に発信しますか？", "", MessageBoxButtons.YesNo) != DialogResult.Yes) return;
                }
                Acx_OnMakeCallRequest();
            }
            if (tel.Length < 1) return;
            Regex rex = new Regex("[\\D]", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline);
            tel = rex.Replace(tel, "");
            lblMsg.Text = "Tel:" + tel;
            if (tel.Length < 1) return;
            //window.external.showMe();
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("AgentStatusID", g_sAgentStatusId);
            objUmParams.AddString("iniFile", "iniFile");
            objUmParams.AddString("Section", "Section");
            objUmParams.AddString("Parameter", "Parameter");
            SendEvent("UM_AGENT_LIST", objUmParams);
        }
        private void CmdDisconnect()
        {
            // UM_DISCONNECT
            CpfParams objUmParams = new CpfParams();
            SendEvent("UM_DISCONNECT", objUmParams);
            //add,xzg,SFA,2010/06/17,skyCall,S-------
            if (g_iMakeCall == 1 && (STATE_CALLING == g_nAgentStatus || STATE_NMCALLING == g_nAgentStatus))
            {
                g_iMakeCall = 0;
                //deleted by Zaric 2012/09/13
                //closeMakeCall("6", g_EventID);
                //end deleted
            }
            SetAgentDisable();
        }
        private void CmdBgnHold()
        {
            Thread.Sleep(100);
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("vASI", "HOLDCALL");
            objUmParams.AddString("vParams", "vParams");
            objUmParams.AddString("iShakeOff", "0");
            SendEvent("UM_BGN_HOLD", objUmParams);
            SetAgentDisable();
        }
        private void CmdEndHold()
        {
            Thread.Sleep(100);
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("iRetrieveRule", "0");
            SendEvent("UM_END_HOLD", objUmParams);
            SetAgentDisable();
        }
        private void CmdGetList()
        {
            g_cmdGetList = 1;

            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("AgentStatusID", g_sAgentStatusId);
            objUmParams.AddString("vIniFile", "");
            objUmParams.AddString("vSection", "Transfer");
            objUmParams.AddString("vParameter", ";iAgentStatus=0");

            SendEvent("UM_GET_LIST", objUmParams);
            if (g_cmdGetList == 1) SetAgentDisable();
            g_objListParams.Clear();
            g_nListCnt = 0;
        }
        private void CmdForwardCnf()
        {
            g_TransConnected = "1";
            CpfParams objUmParams = new CpfParams();
            SendEvent("UM_FORWARD_CNF", objUmParams);
            SetAgentDisable();
        }
        private void CmdCancelForward()
        {
            //add,xzg,2010/02/09,S----------
            g_TransConnected = "0";
            //add,xzg,2010/02/09,E----------

            // UM_CANCEL_FORWARD
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("vReason", "vReason");
            SendEvent("UM_CANCEL_FORWARD", objUmParams);
            SetAgentDisable();
        }
        private void CmdMessage()
        {
            CpfParams objUmParams = new CpfParams();
            string sMessage = txtMessageSend.Text;
            if (sMessage.Length < 1) return;
            if (this.txtMessageHistory.Text.Length > 0)
            {
                txtMessageHistory.Text = txtMessageHistory.Text + "\r\n" + "<" + sMessage;
            }
            else
            {
                txtMessageHistory.Text = "<" + sMessage;
            }
            //recMsg.scrollTop = recMsg.scrollHeight;
            objUmParams.AddString("vMessage", sMessage);
            SendEvent("UM_MESSAGE", objUmParams);
            txtMessageSend.Text = "";

            // List clear
            g_objListParams.Clear();
            g_nListCnt = 0;
        }
        private void CmdBgnRecord()
        {
            CpfParams objUmParams = new CpfParams();
            SendEvent("UM_BGN_RECORDING", objUmParams);
            SetAgentDisable();
        }
        private void CmdEndRecord()
        {
            CpfParams objUmParams = new CpfParams();
            SendEvent("UM_END_RECORDING", objUmParams);
            SetAgentDisable();
        }
        private void CmdConference()
        {
            // UM_GET_LIST
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("vIniFile", "");
            objUmParams.AddString("vSection", "Conference");
            objUmParams.AddString("vParameter", ";iAgentStatus=0");
            if (g_iHelp == 0)
            {
                SendEvent("UM_HELP_ON", objUmParams);
                g_iHelp = 1;
            }
            else
            {
                SendEvent("UM_HELP_OFF", objUmParams);
                g_iHelp = 0;
            }
            // List clear
            g_objListParams.Clear();
            g_nListCnt = 0;
        }
        private void CmdConferenceCnf()
        {
            CpfParams objUmParams = new CpfParams();
            SendEvent("UM_HELP_OFF", objUmParams);
            SetAgentDisable();
        }
        private void CmdMonitor()
        {
            // UM_GET_LIST
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("vIniFile", "");
            objUmParams.AddString("vSection", "Monitoring");
            objUmParams.AddString("vParameter", ";iAgentStatus=4");
            SendEvent("UM_GET_LIST", objUmParams);
            // List clear
            g_objListParams.Clear();
            g_nListCnt = 0;
        }
        private void CmdCancelMeeting()
        {
            // UM_CANCEL_MEETING
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("vReason", "vReason");
            SendEvent("UM_HELP_OFF", objUmParams);
            SetAgentDisable();

        }
        private void CmdMeetingLeave()
        {
            // UM_MEETING_LEAVE
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("vReason", "vReason");
            SendEvent("UM_HELP_OFF", objUmParams);
            SetAgentDisable();
        }
        private void CmdOffhook()
        {
            // UM_ANSWERCALL
            CpfParams objUmParams = new CpfParams();
            SendEvent("UM_ANSWERCALL", objUmParams);
            SetAgentDisable();
        }
        private void CmdRecordList()
        {
            string postData = "u=" + _ResProfile.AgentID + "&ln=" + Language + "&formName=agentMain&upwd=" + _ResProfile.AgentPassword;
            string url = _ResProfile.UserUrl + "agentpanel_record.asp";
            CommonFunction.IEOpenOnURL(url, postData, 700, 600, false);
        }
        private void OnCpfMsgOpen()
        {
            ResProfile res = new ResProfile();
            string sAgentId = res.AgentID;
            string sPhoneNo = res.Logon;
            string strHostName = Dns.GetHostName();
            IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
            string sIpAddr = ipEntry.AddressList[0].ToString();

            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("vStationAddr", sPhoneNo);
            objUmParams.AddString("iAgentID", sAgentId);
            objUmParams.AddString("vInfo", sIpAddr);
            string sPassword = res.AgentPassword;
            objUmParams.AddString("vPassword", sPassword);

            if (res.blSoftPhone)
            {
                objUmParams.AddLong("iConnType", 1);
            }
            else
            {
                objUmParams.AddLong("iConnType", 0);
            }
            SendEvent("UM_LOGON", objUmParams);
        }
        private void CmdCallBack() { }
        private void CmdLogoff()
        {
            if (1 != g_ReRoute)
            {
                g_iLogOff = 1;
            }
            _Timer.Enabled = false;
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("Reason", "Reason");
            SendEvent("UM_LOGOUT", objUmParams);
            // SetAgentStatus
            this.cmbTeleGroup.Items.Clear();
            SetAgentDisable();
        }
        #endregion

        #region receive message operation
        private void SmLogonCnf(CpfParams objSmParams)
        {
            ResProfile res = new ResProfile();
            string displayName = objSmParams.GetStringDefault("vDisplayName", "");
            string sPhone = res.Logon;
            string title = "";
            if (displayName == "") title = sPhone;
            else title = displayName + "(" + sPhone + ")";
            this.Text = _ResourceManager.GetString("AP0040001");

            _Timer.Tick += new EventHandler(timer_Elapsed);
            _Timer.Interval = g_iKeepAlive;
            _Timer.Enabled = true;
            int nCount = int.Parse(objSmParams.GetStringDefault("Count", "0"));
            CpfParams objAcxGroupParams = new CpfParams();
            objAcxGroupParams.AddString("gCount", objSmParams.GetStringDefault("Count", "0"));
            int nAdd = 0;
            for (int i = 1; i <= nCount; i++)
            {
                string sID = objSmParams.GetStringDefault("ID" + i.ToString(), "");
                string sDisp = objSmParams.GetString("Disp" + i.ToString());
                objAcxGroupParams.AddString("gID" + i.ToString(), sID);
                objAcxGroupParams.AddString("gDisp" + i.ToString(), sDisp);
                if (sID != "")
                {
                    nAdd = i;
                    ListItem item = new ListItem(sID, sDisp);
                    cmbTeleGroup.Items.Add(item);
                }
            }
            cmbTeleGroup.SelectedIndex = 0;
            g_iLogOff = 2;
            // SetAgentStatus
            SetAgentStatusByLoginOn();
            //add,xzg,2010/03/02,S----------
            if (STATE_WAIT == g_RebootAgentStatus)
            {
                CmdBgnWait();
                g_RebootAgentStatus = STATE_LOGOFF;
            }
            else if (STATE_WORKTIME == g_RebootAgentStatus)
            {
                g_clickWork = 1;
                CmdBgnWorktime();
                g_RebootAgentStatus = STATE_LOGOFF;
            }
            else if (STATE_SEATOFF == g_RebootAgentStatus)
            {
                CmdBgnSeatoff();
                g_RebootAgentStatus = STATE_LOGOFF;
            }
            //add,xzg,2010/03/02,E----------
        }
        private void SmLogonErr(CpfParams objSmParams)
        {
            _CpfMsg.Close();
            string vReason = objSmParams.GetString("vReason");
            var vErrMsg = "";
            if ("__NONE__" == vReason)
            {
                g_ResultCodeEx = 1001;
                if (g_AcxOnConnect != 1)
                    MessageBox.Show(_ResourceManager.GetString("AP9990008"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ("__EXPIRE__" == vReason)
            {
                g_ResultCodeEx = 1002;
                if (g_AcxOnConnect != 1)
                {
                    MessageBox.Show(_ResourceManager.GetString("AP9990009"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    frmWebPage frm = new frmWebPage();
                    frm.ShowDialog();
                }

            }
            else if ("__DISABLE__" == vReason)
            {
                g_ResultCodeEx = 1003;
                if (g_AcxOnConnect != 1)
                    MessageBox.Show(_ResourceManager.GetString("AP9990010"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ("__SAME__" == vReason)
            {
                g_ResultCodeEx = 1004;
                if (g_AcxOnConnect != 1)
                {
                    MessageBox.Show(_ResourceManager.GetString("AP9990011"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    frmWebPage frm = new frmWebPage();
                    frm.ShowDialog();
                }
            }
            else if ("__AGENT__" == vReason)
            {
                g_ResultCodeEx = 1005;
                if (g_AcxOnConnect != 1)
                    MessageBox.Show(_ResourceManager.GetString("AP9990012"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ("__STATION__" == vReason)
            {
                g_ResultCodeEx = 1006;
                if (g_AcxOnConnect != 1)
                    MessageBox.Show(_ResourceManager.GetString("AP9990013"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ("EXPIRED" == vReason)
            {
                g_ResultCodeEx = 1007;
                if (g_AcxOnConnect != 1)
                    MessageBox.Show(_ResourceManager.GetString("AP9990014"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ("DISABLE" == vReason)
            {
                g_ResultCodeEx = 1008;
                if (g_AcxOnConnect != 1)
                    MessageBox.Show(_ResourceManager.GetString("AP9990015"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ("LN_OVER" == vReason)
            {
                g_ResultCodeEx = 1009;
                if (g_AcxOnConnect != 1)
                    MessageBox.Show(_ResourceManager.GetString("AP9990016"), _ResourceManager.GetString("AP9990004"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                g_ResultCodeEx = 1010;
                vErrMsg = _ResourceManager.GetString("AP9990004");
                if (g_AcxOnConnect != 1)
                    MessageBox.Show(_ResourceManager.GetString("AP9990007") + vErrMsg,
                            "Logon", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (g_AcxOnConnect == 1)
            {
                g_ResultCode = 0;
                CpfParams objRetParams = new CpfParams();
                g_nAgentStatus = STATE_LOGOFF;
                g_PreAgentStatus = -1;
                g_PreCallStatus = -1;
                _LpcSvr.SendEvent("OnChangeAgentState", objRetParams.GetParams());
            }
            // SetAgentStatus
            SetAgentStatusDefault();
        }
        private void SmLogoffCnf(CpfParams objSmParams)
        {
            SmLogoff(objSmParams);
        }
        private void SmLogoff(CpfParams objSmParams)
        {
            Acx_OnServiceStopped(0);
            g_PreAgentStatus = -1;
            g_PreCallStatus = -1;
            _CpfMsg.Close();
            this.Text = _ResourceManager.GetString("AP0040001");
            //this.Icon=(PANELICON_ERROR);
            this.cmbTeleGroup.Items.Clear();
            g_iHelp = 2;
            SetAgentStatusDefault();
            if (1 == g_ReRoute)
            {
                Thread.Sleep(3000);
                CmdLogon();
                SetAgentDisable();
            }
            g_ReRoute = 0;

        }
        private void SmSendCnf(CpfParams objSmParams)
        {

        }
        private void SmActivity(CpfParams objSmParams)
        {
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("AgentStatusID", g_sAgentStatusId);
            objUmParams.AddString("Reason", "Reason");
            SendEvent("UM_ACTIVITY_RSP", objUmParams);
        }
        private void SmMessageInd(CpfParams objSmParams)
        {
            onShowMsg();
            string msg = objSmParams.GetStringDefault("vMessage", "");
            Acx_OnDataReceived(msg);
            if (this.txtMessageHistory.Text.Length > 0)
            {
                txtMessageHistory.Text = txtMessageHistory.Text + "\r\n" + ">" + msg;
            }
            else
            {
                txtMessageHistory.Text = ">" + msg;
            }
        }
        private void SmStatus(CpfParams objSmParams)
        {
            if (g_nAgentStatus == STATE_OFFERING || STATE_CONNECT > 0 || STATE_WORKTIME > 0)
            {
                if (frmPhoneCome != null)
                {
                    Thread.Sleep(100);
                    try
                    {
                        //g_OfferingWindow.OnCancelByOtherWindow() ;
                        this.frmPhoneCome.Dispose();
                    }
                    catch (Exception e)
                    {

                    }
                    frmPhoneCome = null;
                }

            }

            int nStatus = objSmParams.GetLongDefault("iStatus", 0);
            string vReason = objSmParams.GetStringDefault("vReason", "");
            if (nStatus == 13) nStatus = STATE_CONNECT;
            iNumberOfVmail = objSmParams.GetLongDefault("iNumberOfVmail", 0);

            if (iNumberOfVmail > 0)
                this.picVoiceMail.Image = Image.FromFile("Image\\PanelButtonMail1.jpg");
            else
                this.picVoiceMail.Image = null;

            iNumberOfQueCall = objSmParams.GetLongDefault("iNumberOfQueCall", 0);
            if (iNumberOfQueCall > 3)
                this.picQueCall.Image = Image.FromFile("Image\\PanelButtonQue2.jpg");
            else if (iNumberOfQueCall > 0)
                this.picQueCall.Image = Image.FromFile("Image\\PanelButtonQue1.jpg");
            else
                this.picQueCall.Image = Image.FromFile("Image\\PanelButtonQue0.jpg");

            Acx_OnChangeQueVoice();

            if (STATE_NMCALLING == nStatus || STATE_TRANCALLING == nStatus)
            {
                if (playVoice == 0 && g_ClientName != "SFA")
                {
                    PlaySound(Application.StartupPath + @"\sound\ring.wav", new IntPtr(), playSound.SND_LOOP | playSound.SND_ASYNC);
                    playVoice = 1;
                }

            }
            else
            {
                //deleted by Zaric 2012/09/13
                //objSound.innerHTML='<embed id="bgsound2" src="sounds/ring.wav" loop="true" autostart="false" style="width:0px;height:0px;visibility:hidden;">';
                //end deleted
                playVoice = 0;
            }
            if (g_iCallBack == 1 && nStatus == STATE_WORKTIME)
            {
                g_iCallBack = 0;
                //deleted by Zaric 2012/09/13
                //closeCallBack();
                //end deleted
            }

            //skyCallID=objSmParams.GetStringDefault("iSessionProfileID","0");

            if (g_iMakeCall == 1 && nStatus == STATE_WORKTIME)
            {
                g_iMakeCall = 0;
                //deleted by Zaric 2012/09/13
                //closeMakeCall(vReason,g_EventID);
                //end deleted
            }
            var strMsg = "";
            if (vReason.Length > 0)
            {
                if (REQUEST_403 == vReason)
                {
                    strMsg = this._ResourceManager.GetString("AP0040037");
                    strMsg = strMsg + "(403)";
                    lblInfoMsg.Text = strMsg;
                    Acx_OnCallFailed(objSmParams, 403);
                }
                else if (REQUEST_486 == vReason)
                {
                    strMsg = this._ResourceManager.GetString("AP0040038");
                    strMsg = strMsg + "(486)";
                    lblInfoMsg.Text = strMsg;
                    Acx_OnCallFailed(objSmParams, 486);
                }
                else
                {
                    if (vReason.CompareTo(REQUEST_400) >= 0)
                    {
                        Regex rex = new Regex("/^[0-9]+$/");
                        if (null != rex.Match(vReason))
                        {
                            strMsg = this._ResourceManager.GetString("AP0040037");
                            strMsg = strMsg + "(" + vReason + ")";
                            lblInfoMsg.Text = strMsg;
                            Acx_OnCallFailed(objSmParams, int.Parse(vReason));
                        }
                    }
                }
            }
            g_nAgentStatus = nStatus;
            Acx_OnChangeAgentState(objSmParams);
            if (STATE_CONNECT == nStatus)
            {
                Acx_OnConnected(objSmParams);
            }
            //add,xzg,acx,E----
            SetAgentStatus(nStatus);
        }
        private void SmConnectCnf(CpfParams objSmParams)
        {
        }
        private void SmDisconnectCnf(CpfParams objSmParams)
        {
            Acx_OnDisconnected(objSmParams);
        }
        private void SmOfferingInd(CpfParams objSmParams)
        {
            g_CallType = "2";
            if (g_AcxOnConnect == 0 || this.WindowState == FormWindowState.Minimized)
            {
                this.Show();
                this.WindowState = FormWindowState.Normal;
            }
            g_vCallerID = objSmParams.GetStringDefault("vCallerID", "");
            g_CustomerName = objSmParams.GetStringDefault("CustomerName", "");
            g_iTimeOut = int.Parse(objSmParams.GetStringDefault("iTimeout", "0"));
            int hasOption = 0;
            for (int i = 0; i < this.cmbCallerList.Items.Count; i++)
            {
                if ((cmbCallerList.Items[i] as ListItem).Value == g_vCallerID)
                {
                    hasOption = 1;
                    break;
                }
            }
            if (hasOption == 0)
            {
                var oOption = new ListItem(g_vCallerID, g_vCallerID);
                this.cmbCallerList.Items.Add(oOption);
            }
            g_vTel = g_vCallerID;
            string msg1 = "";
            string msg2 = "";
            string nCaller = objSmParams.GetStringDefault("vCallerID", "");
            string nSkill = objSmParams.GetStringDefault("vDistGroup", "");

            string nGroup = objSmParams.GetStringDefault("vIncmGroup", "");
            g_vGrp = nGroup;
            g_vSkillGrp = nSkill;
            //add,xzg,2009/12/21,S-----
            Acx_OnOffering(objSmParams);
            //add,xzg,2009/12/21,E-----

            //神田商会
            //nGroup="神田着信"
            //nSkill="神田着信"
            msg1 = _ResourceManager.GetString("AP0040040");
            msg1 = msg1 + "(" + g_vSkillGrp + ")";
            msg1 = msg1 + "  " + _ResourceManager.GetString("AP0040039") + "(" + nGroup + ")";
            msg2 = _ResourceManager.GetString("AP0040041") + "(" + nCaller + ")";

            if (nGroup != "") lblMsg.Text = msg1;
            if (nCaller != "") lblInfoMsg.Text = msg2;
            g_objOffParams = objSmParams;

            if (g_AcxOnConnect == 0 || this.WindowState == FormWindowState.Minimized || g_ClientName == "SFA")
            {
                string ty = objSmParams.GetStringDefault("vFuncType", "0");
                frmPhoneCome = new frmPhoneCome(this);
                frmPhoneCome.ln = Language;
                frmPhoneCome.ty = ty;
                frmPhoneCome.Width = 290;
                frmPhoneCome.Height = 300;
                frmPhoneCome.ShowDialog();
            }
            else
            {

                string iofferingTimeout = objSmParams.GetStringDefault("iTimeout", "0");
                if (iofferingTimeout != "UNKOWN")
                {
                    var times = 0;
                    times = int.Parse(iofferingTimeout);
                    times = times * 1000;
                    if (times > 0)
                    {
                        _OfferingTimeOut.Tick += new EventHandler(_OfferingTimeOut_Elapsed);
                        _OfferingTimeOut.Interval = times;
                        _OfferingTimeOut.Enabled = true;

                    }
                }
            }
        }
        private void SmAgentListResult(CpfParams objSmParams)
        {
            CpfParams objUmParams = new CpfParams();
            string tel = "";
            if (this.cmbCallerList.Visible)
            {
                tel = (this.cmbCallerList.SelectedItem as ListItem).Value;
            }
            else
            {
                tel = this.txtTeleNo.Text;
            }

            if (tel.Length < 1)
            {
                tel = System.Windows.Forms.Clipboard.GetData("text").ToString();
                if (tel.Length < 1) return;
            }
            Regex rex = new Regex("[\\D]", System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline);
            tel = rex.Replace(tel, "");
            if (tel.Length < 1) return;
            if (g_nAgentStatus == STATE_HOLDING)
            {
                string sAgentStatusID = "TRAN#" + tel;
                objUmParams.AddString("iAgentStatusID", sAgentStatusID);
                SendEvent("UM_FORWARD", objUmParams);
            }
            else
            {
                string groupid = (this.cmbTeleGroup.SelectedItem as ListItem).Key;
                if (groupid.Length > 0)
                    objUmParams.AddString("iGroupID", groupid);
                objUmParams.AddString("vAddr", tel);
                SendEvent("UM_CONNECT", objUmParams);
                g_CallType = "1";
            }
            SetAgentDisable();
            int hasOption = 0;
            for (int i = 0; i < this.cmbCallerList.Items.Count; i++)
            {
                if ((this.cmbCallerList.Items[i] as ListItem).Value == tel)
                {
                    hasOption = 1;
                    break;
                }
            }
            if (0 == hasOption)
            {
                var oOption = new ListItem(tel, tel);
                this.cmbCallerList.Items.Add(oOption);
            }
        }
        private void SmGetListResult(CpfParams objSmParams)
        {
            // Add List
            int nCount = objSmParams.GetLongDefault("Count", 0);
            for (int i = 1; i <= nCount; i++)
            {
                string sID = objSmParams.GetString("ID" + i.ToString());
                string sDisp = objSmParams.GetString("Disp" + i.ToString());
                g_nListCnt = g_nListCnt + 1;
                g_objListParams.AddString("ID" + g_nListCnt.ToString(), sID);
                g_objListParams.AddString("Disp" + g_nListCnt.ToString(), sDisp);
            }
            if (objSmParams.GetStringDefault("Continue", "S") == "C") return;
            string sSection = objSmParams.GetStringDefault("vSection", "Transfer");

            // 選択ダイヤログ
            g_objListParams.AddLong("Count", g_nListCnt);
            if (g_cmdGetList == 0)
            {
                g_objAgentList = g_objListParams;
                g_getAgentList = 1;
                return;
            }
            if (sSection == "Message")
            {
                //sRet = window.external.ShowModalDialog(
                //        "agentpanel_select_chat.htm", g_objListParams,
                //        "dialogWidth:600px;dialogHeight:300px;center:yes;status:no");
            }
            else
            {
                FrmSelectFoward frmSelectForward = new FrmSelectFoward(this);
                frmSelectForward.Width = 300;
                frmSelectForward.Height = 220;
                frmSelectForward.ShowDialog();
            }

            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("AgentStatusID", g_sAgentStatusId);

            // UM_FORWARD
            if (sSection == "Transfer")
            {
                if (_strReturnValueFromSelectForward != "cancel")
                {

                    CpfParams objUmParams1 = new CpfParams();
                    objUmParams1.AddString("iSessionProfileID", g_EventID);
                    objUmParams1.AddString("iMatterID", g_CallType);
                    SendEvent("UM_SET_CUST_INFO", objUmParams1);

                    objUmParams.AddString("iAgentStatusID", _strReturnValueFromSelectForward.ToString());
                    objUmParams.AddString("vMediaType", "1");
                    SendEvent("UM_FORWARD", objUmParams);
                    //SetAgentDisable();
                    SetAgentDisable();
                }
                else
                {
                    SetAgentStatus(STATE_HOLDING);
                }
            }
            else if (sSection == "Conference")
            {
            }
            else if (sSection == "Monitoring")
            {
            }
            else if (sSection == "Message")
            {
                if (_strReturnValueFromSelectForward != "cancel")
                {
                    string sMessage = _strReturnValueFromSelectForward.ToString();
                    objUmParams.AddString("vMessage", sMessage);
                    nCount = 1;
                    string str = "ok";
                    objUmParams.AddString("Count", nCount.ToString());

                    for (int i = 1; i <= nCount; i++)
                    {
                        objUmParams.AddString("ID" + i.ToString(), str);
                    }
                    SendEvent("UM_MESSAGE", objUmParams);
                }
            }
            else
            {
                if (_strReturnValueFromSelectForward != "cancel")
                {
                    //add,xzg,2010/02/09,S---------------
                    CpfParams objUmParams1 = new CpfParams();
                    objUmParams1.AddString("iSessionProfileID", g_EventID);
                    objUmParams1.AddString("iMatterID", g_CallType);
                    SendEvent("UM_SET_CUST_INFO", objUmParams1);
                    //add,xzg,2010/02/09,E---------------

                    objUmParams.AddString("iAgentStatusID", _strReturnValueFromSelectForward.ToString());
                    objUmParams.AddString("vMediaType", "1");
                    SendEvent("UM_FORWARD", objUmParams);
                    SetAgentDisable();
                }
                else
                {
                    SetAgentStatus(STATE_HOLDING);
                }
            }
        }
        private void SmForwardAck(CpfParams objSmParams) { }
        private void SmForwardNak(CpfParams objSmParams)
        {
            MessageBox.Show(_ResourceManager.GetString("AP9990019"), _ResourceManager.GetString("AP9990020"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
        }
        private void SmForwardInd(CpfParams objSmParams)
        {
            //// ShowModalDialog
            //sRet = window.external.ShowModalDialog(
            //            "agentpanel_forwardind.htm", objSmParams,
            //            "dialogWidth:600px;dialogHeight:300px;center:yes;status:no");
            //// UM_FORWARD_ACK
            //CpfParams objUmParams = new CpfParams();
            //objUmParams.AddString("AgentStatusID", g_sAgentStatusId);
            //if (sRet == "ok")
            //{
            //    objUmParams.AddString("Reason", "Reason");
            //    SendEvent("UM_FORWARD_ACK", objUmParams);
            //    SetAgentDisable();
            //}
            //else
            //{
            //    objUmParams.AddString("Reason", "Reason");
            //    SendEvent("UM_FORWARD_NAK", objUmParams);
            //}
        }
        private void SmForwardErr(CpfParams objSmParams)
        {
            MessageBox.Show(_ResourceManager.GetString("AP9990021"), _ResourceManager.GetString("AP9990020"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
        }
        private void SmPlayListResult(CpfParams objSmParams)
        {
            int nCount = objSmParams.GetLong("Count");
            for (int i = 1; i < nCount; i++)
            {
                string sID = objSmParams.GetString("ID" + i.ToString());
                string sDisp = objSmParams.GetString("Disp" + i.ToString());
                g_nListCnt = g_nListCnt + 1;
                g_objListParams.AddString("ID" + g_nListCnt.ToString(), sID);
                g_objListParams.AddString("Disp" + g_nListCnt.ToString(), sDisp);
            }
            if (objSmParams.GetStringDefault("Continue", "S") == "C") return;

            CpfParams objUmParams = new CpfParams();
            objUmParams.AddLong("AgentStatusID", int.Parse(g_sAgentStatusId));
        }
        private void SmMonitoringAck(CpfParams objSmParams) { }
        private void SmMonitoringNak(CpfParams objSmParams)
        {
            MessageBox.Show(_ResourceManager.GetString("AP9990022"), _ResourceManager.GetString("AP9990023"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
        }
        private void SmMeetingAck(CpfParams objSmParams) { }
        private void SmMeetingNak(CpfParams objSmParams)
        {
            MessageBox.Show(_ResourceManager.GetString("AP9990024"), _ResourceManager.GetString("AP9990025"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
        }
        private void SmEndRecording(CpfParams objSmParams)
        {
            string sRecFile = objSmParams.GetString("iBoxProfileID");
        }
        private void SmRebooted(CpfParams objSmParams)
        {
            g_RebootAgentStatus = g_nAgentStatus;
            g_iLogOff = 1;
            SmLogoff(objSmParams);
            Thread.Sleep(3000);
            CmdLogon();
        }
        public void SmOfferingAck()
        {
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("AgentStatusID", g_sAgentStatusId);
            SendEvent("UM_OFFERING_ACK", objUmParams);
            SetAgentDisable();
        }
        public void SmOfferingNak()
        {
            CpfParams objUmParams = new CpfParams();
            objUmParams.AddString("AgentStatusID", g_sAgentStatusId);
            SendEvent("UM_OFFERING_NAK", objUmParams);
            SetAgentDisable();
        }
        private void SmReroute(CpfParams objSmParams)
        {
            g_RebootAgentStatus = g_nAgentStatus;
            string sIpAddr = objSmParams.GetStringDefault("sIpAddr", "");
            string iPort = objSmParams.GetStringDefault("iPort", "");
            string sServer = objSmParams.GetStringDefault("sServer", "");
            _ServerName = sServer;
            _ServerIP = sIpAddr;
            _Port = int.Parse(iPort);
            g_ReRoute = 1;
            g_iLogOff = 1;
            CmdLogoff();
        }
        private void SmGetSkillGroup(CpfParams objSmParams)
        {
            string sID = objSmParams.GetStringDefault("iSkillID", "");
            string sName = objSmParams.GetStringDefault("vSkillName", "");
            int listCount = g_objGroupList.m_nCount;
            listCount = listCount / 2 + 1;
            g_objGroupList.AddString("ID" + listCount.ToString(), sID);
            g_objGroupList.AddString("Disp" + listCount.ToString(), sName);
        }
        private void SmKeepAlive(CpfParams objSmParams)
        {
            iNumberOfVmail = int.Parse(objSmParams.GetStringDefault("iNumberOfVmail", "0"));

            if (iNumberOfVmail > 0)
                this.picVoiceMail.Image = Image.FromFile("Image\\PanelButtonMail1.jpg");
            else
                this.picVoiceMail.Image = null;

            iNumberOfQueCall = objSmParams.GetLongDefault("iNumberOfQueCall", 0);
            if (iNumberOfQueCall > 3)
                this.picQueCall.Image = Image.FromFile("Image\\PanelButtonQue2.jpg");
            else if (iNumberOfQueCall > 0)
                this.picQueCall.Image = Image.FromFile("Image\\PanelButtonQue1.jpg");
            else
                this.picQueCall.Image = Image.FromFile("Image\\PanelButtonQue0.jpg");

            //add,xzg,SFA,S
            Acx_OnChangeQueVoice();
            //add,xzg,SFA,E
            return;
            //iNumberOfVmail = int.Parse(objSmParams.GetStringDefault("iNumberOfVmail", "0"));
            //iNumberOfQueCall = int.Parse(objSmParams.GetStringDefault("iNumberOfQueCall", "0"));
            //if (g_nAgentStatus == STATE_WORKTIME)
            //{
            //    //var objButton;
            //    var vMsg = "";
            //    if (iNumberOfVmail > 0)
            //    {
            //        //objButton = document.getElementById(g_aButtonInfo[BTN_CALLBACK][0]);
            //        //objButton.className = g_aButtonInfo[BTN_CALLBACK][202];

            //        if (lblMsg.Text.Trim() == "")
            //        {
            //            vMsg = _ResourceManager.GetString("AP0040042");
            //            vMsg = vMsg + iNumberOfVmail;
            //            vMsg = vMsg + _ResourceManager.GetString("AP0040043");
            //            lblMsg.Text = vMsg;
            //        }

            //    }
            //    if (iNumberOfQueCall > 0)
            //    {
            //        //objButton = document.getElementById(g_aButtonInfo[BTN_WAIT][0]);
            //        //objButton.className = g_aButtonInfo[BTN_WAIT][202];
            //        if (this.lblInfoMsg.Text.Trim() == "")
            //        {
            //            vMsg = _ResourceManager.GetString("AP0040044");
            //            vMsg = vMsg + iNumberOfQueCall;
            //            vMsg = vMsg + _ResourceManager.GetString("AP0040045");
            //            lblInfoMsg.Text = vMsg;
            //        }

            //    }
            //}
        }
        #endregion

        private void Acx_OnDisconnected(CpfParams objArgParams)
        {
            objArgParams = new CpfParams();
            objArgParams.AddLong("nEventId", int.Parse(objArgParams.GetStringDefault("iSessionProfileID", "0")));
            _LpcSvr.SendEvent("OnDisconnected", objArgParams.GetParams());
            g_ResultCode = 1;
        }
        private void Acx_OnServiceStopped(int nResult)
        {
            CpfParams objArgParams = new CpfParams();
            objArgParams.AddLong("nResult", nResult);
            _LpcSvr.SendEvent("OnServiceStopped", objArgParams.GetParams());
        }
        private void Acx_OnChangeQueVoice()
        {

            CpfParams objArgParams = new CpfParams();
            objArgParams.AddLong("Voicemail", iNumberOfVmail);
            objArgParams.AddLong("QueCall", iNumberOfQueCall);
            _LpcSvr.SendEvent("OnChangeQueVoice", objArgParams.GetParams());
        }
        private void Acx_OnCallFailed(CpfParams objArgParams, int nResult)
        {
            g_ResultCodeEx = 2000 + nResult;
            objArgParams = new CpfParams();
            objArgParams.AddLong("nEventId", int.Parse(g_EventID));
            objArgParams.AddLong("nResult", nResult);
            _LpcSvr.SendEvent("OnCallFailed", objArgParams.GetParams());

        }
        private void Acx_OnChangeCallState(CpfParams objArgParams)
        {
            _LpcSvr.SendEvent("OnChangeCallState", objArgParams.GetParams());
        }
        private void Acx_OnConnected(CpfParams objArgParams)
        {
            g_HasConneted = 1;
            if (g_AcxAgentTrans == 1)
            {
                if (g_TransConnected == "0") g_TransConnected = "1";
            }
            CpfParams objSetParams = new CpfParams();
            objArgParams.AddLong("nEventId", int.Parse(objArgParams.GetStringDefault("iSessionProfileID", "0")));
            _LpcSvr.SendEvent("OnConnected", objArgParams.GetParams());

        }
        private void Acx_OnChangeAgentState(CpfParams objArgParams)
        {
            int curCallStatus = -1;
            int curAgentStatus = -1;
            string sessionID = objArgParams.GetStringDefault("iSessionProfileID", "NONE");
            if (sessionID.Length > 0 && sessionID != "NONE")
            {
                g_EventID = sessionID;
            }
            //wait
            if (g_nAgentStatus == STATE_WAIT)
            {
                curAgentStatus = 0;
            }
            //Work
            else if (g_nAgentStatus == STATE_WORKTIME)
            {
                curAgentStatus = 1;
            }
            //seatoff
            else if (g_nAgentStatus == STATE_SEATOFF)
            {
                curAgentStatus = 2;
            }
            //busy
            else if (g_nAgentStatus == 1)
            {
                curAgentStatus = 4;
            }
            else
            {
                curAgentStatus = 3;
            }
            if (g_nAgentStatus == STATE_LOGOFF)
            {
                _LpcSvr.SendEvent("OnChangeAgentState", objArgParams.GetParams());
                return;
            }

            if (STATE_TRANSFERING == g_nAgentStatus || STATE_TRANOFFERING == g_nAgentStatus
                || STATE_TRANCALLING == g_nAgentStatus)
                g_TransConnected = "0";

            if (curAgentStatus != g_PreAgentStatus)
            {
                CpfParams objRetParams = new CpfParams();
                if (g_PreAgentStatus == 3)
                {
                    g_TelNo = objArgParams.GetStringDefault("vCaller", "");
                    if (g_TelNo != "")
                        //g_TelNo=g_TelNo.Replace(new Regex("[^0-9]","gm"),"");
                        g_CallDateE = DateTime.Now.ToString();
                    objRetParams.AddString("nEventId", g_EventID);
                    objRetParams.AddString("CallStartTime", g_CallDateS);
                    objRetParams.AddString("CallEndTime", g_CallDateE);
                    objRetParams.AddString("CallType", g_CallType);
                    objRetParams.AddString("TelNo", g_TelNo);
                    string vReason = objArgParams.GetStringDefault("vReason", "");
                    if (vReason != "0") vReason = "1";
                    //add,xzg,acx,2010/02/09,S---------
                    if (g_HasConneted == 0) vReason = "1";
                    g_HasConneted = 0;
                    //add,xzg,acx,2010/02/09,E---------
                    objRetParams.AddString("vReason", vReason);
                    //add,xzg,acx,2010/02/09,S---------
                    //add,xzg,acx,2010/02/17,S---------
                    if (g_AcxAgentTrans == 1)
                    {
                        if (vReason == "1")
                            objRetParams.AddString("vCancel", "0");
                        else
                            objRetParams.AddString("vCancel", "1");
                    }
                    else
                    {
                        objRetParams.AddString("vCancel", g_TransConnected);
                    }
                    g_TransConnected = "-1";
                    g_AcxAgentTrans = 0;
                    g_CallType = "-1";

                }
                else if (curAgentStatus == 3)
                {
                    g_CallDateS = DateTime.Now.ToString();
                }
                _LpcSvr.SendEvent("OnChangeAgentState", objRetParams.GetParams());
            }

            g_PreAgentStatus = curAgentStatus;

            if (g_nAgentStatus == STATE_CALLING || g_nAgentStatus == STATE_NMCALLING
                    || g_nAgentStatus == STATE_TRANCALLING)
            {
                curCallStatus = 1;
            }
            else if (g_nAgentStatus == STATE_OFFERING)
            {
                curCallStatus = 2;
            }
            else if (g_nAgentStatus == STATE_CONNECT || g_nAgentStatus == STATE_TRANSFERING
                || g_nAgentStatus == STATE_TRANOFFERING
                )
            {
                curCallStatus = 3;
            }
            else if (g_nAgentStatus == STATE_HOLDING)
            {
                curCallStatus = 4;
            }
            else
            {
                curCallStatus = 0;
            }
            if (g_PreCallStatus == 1 && curCallStatus == 0) g_ResultCodeEx = 2701;
            if (g_PreCallStatus == 2 && curCallStatus == 0) g_ResultCodeEx = 2702;
            if (g_PreCallStatus != curCallStatus) Acx_OnChangeCallState(objArgParams);
            g_PreCallStatus = curCallStatus;
        }
        private void Acx_OnOffering(CpfParams objArgParams)
        {
            string sCallType = objArgParams.GetStringDefault("iMatterID", "");
            if (sCallType == "1" || sCallType == "2") g_CallType = sCallType;
            else g_CallType = "2";

            string agentTrans = objArgParams.GetStringDefault("vFuncType", "0");
            if (agentTrans == "2") g_AcxAgentTrans = 1;
            else g_AcxAgentTrans = 0;
            //add,xzg,acx,2010/02/17,E---------

            string sCallerId = objArgParams.GetStringDefault("vCallerID", "");
            string sCalledId = objArgParams.GetStringDefault("vCalleeID", "");
            //nSkill = objArgParams.GetStringDefault("iSkillID", "");
            string nSkill = objArgParams.GetStringDefault("vDistGroup", "");
            int nEventId = objArgParams.GetLongDefault("iSessionProfileID", 0);
            objArgParams.AddLong("nEventId", nEventId);
            //objArgParams.SetInt("nEventId", objArgParams.GetStringDefault("iSessionProfileID","0"));
            objArgParams.AddString("sCallerId", sCallerId);
            objArgParams.AddString("sCalledId", sCalledId);
            objArgParams.AddString("sAcdGroupId", nSkill);
            //add,SFA,S
            objArgParams.AddString("sGroupId", objArgParams.GetStringDefault("vIncmGroup", ""));
            //add,SFA,E
            // objArgParams <- 追加のデータ
            _LpcSvr.SendEvent("OnOffering", objArgParams.GetParams());
        }
        private void Acx_OnDataReceived(string sMSG)
        {
            CpfParams objArgParams = new CpfParams();
            objArgParams.AddString("sAgentId", "1001");
            objArgParams.AddString("sMSG", sMSG);
            _LpcSvr.SendEvent("OnDataReceived", objArgParams.GetParams());
        }
        private void autoTimeOut()
        {
            try
            {
                _OfferingTimeOut.Enabled = false;
                SmOfferingNak();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        private void KeepAlive()
        {
            try
            {
                CpfParams objUmParams = new CpfParams();
                objUmParams.AddString("vKeepAlive", "1");
                SendEvent("UM_KEEPALIVE", objUmParams);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void SendEvent(string sEvent, CpfParams objParams)
        {
            try
            {
                _CpfMsg.SendEvent("Phase", "Field", sEvent, objParams);
            }
            catch (Exception ex)
            {
                MessageBox.Show("CpfMsgSendEvent() failed: " + ex.Message);
            }
        }

        private void timer_Elapsed(object sender, EventArgs e)
        {
            KeepAlive();
        }
        private void _AutoWait_Elapsed(object sender, EventArgs e)
        {
            autoWait();
        }
        private void _OfferingTimeOut_Elapsed(object sender, EventArgs e)
        {
            autoTimeOut();
        }

        private void SetAgentDisable()
        {
            this.picLogOff.Enabled = false;
            this.picLogon.Visible = true;
            this.picSetting.Enabled = false;
            this.picRecept.Enabled = false;
            this.picOperate.Enabled = false;
            this.picLeave.Enabled = false;
            this.picKeep.Enabled = false;
            this.picFoward.Enabled = false;
            this.picSend.Enabled = false;
            this.picCut.Enabled = false;
            this.picPhoneList.Enabled = false;
            this.picSC.Enabled = false;
            this.picPhoneMessage.Enabled = false;
            this.picHelp.Enabled = false;
            this.picArrow.Enabled = false;
            this.picCT.Enabled = false;
            this.picMyUser.Enabled = false;
            this.picArrow.Enabled = false;
            this.picCT.Enabled = false;
            this.picMyUser.Enabled = false;
        }
        private void SetAgentStatusByLoginOn()
        {
            this.picLogOff.Visible = true;
            //this.picLogOff.BackColor = Color.Blue;
            this.picLogOff.Location = this.picLogon.Location;
            this.picLogOff.Width = this.picLogon.Width;
            this.picLogOff.Height = this.picLogon.Height;
            this.picLogon.Visible = false;
            List<PicBoxStatus> ListPicBox = new List<PicBoxStatus>();
            PicBoxStatus picstatus = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\MainStatusAgent.png"), PictureBox = this.PicStatus };
            //PicBoxStatus piclogin = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040034"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picLogon };
            PicBoxStatus picsetting = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040032"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picSetting, Enabled = false };
            PicBoxStatus picrecept = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040003"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgentH.png"), PictureBox = this.picRecept, Enabled = true };

            PicBoxStatus picoperate = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picOperate, Enabled = false };
            PicBoxStatus picleave = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040016"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picLeave, Enabled = true };
            PicBoxStatus pickeep = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040018"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picKeep, Enabled = false };
            PicBoxStatus picfoward = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040020"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picFoward, Enabled = false };

            PicBoxStatus picsend = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040017"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhoneH.png"), PictureBox = this.picSend, Enabled = true };
            PicBoxStatus piccut = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040028"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picCut, Enabled = false };
            PicBoxStatus picphonelist = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040035"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneList, Enabled = true };
            PicBoxStatus picphonemessage = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040036"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneMessage, Enabled = true };

            PicBoxStatus pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040010"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picHelp, Enabled = true };
            PicBoxStatus picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picArrow, Enabled = true };
            PicBoxStatus picct = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040047"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picCT, Enabled = false };
            PicBoxStatus picmyuser = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040046"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picMyUser, Enabled = true };
            PicBoxStatus piclogoff = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040033"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picLogOff, Enabled = true };
            PicBoxStatus picsky = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040055"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picSKY, Enabled = true };

            //ListPicBox.Add(piclogin);
            ListPicBox.Add(picsetting);
            ListPicBox.Add(picstatus);
            ListPicBox.Add(picrecept);

            ListPicBox.Add(picoperate);
            ListPicBox.Add(picleave);
            ListPicBox.Add(pickeep);
            ListPicBox.Add(picfoward);

            ListPicBox.Add(picsend);
            ListPicBox.Add(piccut);
            ListPicBox.Add(picphonelist);
            ListPicBox.Add(picphonemessage);

            ListPicBox.Add(pichelp);
            ListPicBox.Add(picarrow);
            ListPicBox.Add(picct);

            ListPicBox.Add(picmyuser);
            ListPicBox.Add(piclogoff);
            ListPicBox.Add(picsky);
            PictureBoxTool.DrawPictureBoxList(ListPicBox);
        }
        private void SetAgentStatusDefault()
        {
            SetInitialControl();
        }
        private void SetAgentStatus(int nStatus)
        {
            PicBoxStatus picrecept = null;
            PicBoxStatus picoperate = null;
            PicBoxStatus picphonelist = null;
            PicBoxStatus picmyuser = null;
            PicBoxStatus picstatus = null;
            PicBoxStatus picsetting = null;
            PicBoxStatus picleave = null;
            PicBoxStatus pickeep = null;
            PicBoxStatus picfoward = null;
            PicBoxStatus picsend = null;
            PicBoxStatus piccut = null;
            PicBoxStatus picphonemessage = null;
            PicBoxStatus picunKeep = null;
            PicBoxStatus pichelp = null;
            PicBoxStatus picarrow = null;
            PicBoxStatus picct = null;
            PicBoxStatus piclogoff = null;
            PicBoxStatus picsky = null;
            // Save
            g_nAgentStatus = nStatus;
            if (STATE_WORKTIME == nStatus)
            {

                var time = 0;
                time = g_WaitTime * 1000;

                if (time > 0 && 1 != g_isSetWatiTime)
                {
                    g_isSetWatiTime = 1;
                    _AutoWait.Interval = time;
                    _AutoWait.Tick += new EventHandler(_AutoWait_Elapsed);
                    _AutoWait.Enabled = true;
                }
            }
            else
            {
                if (1 == g_isSetWatiTime)
                {
                    g_isSetWatiTime = 0;
                    _AutoWait.Enabled = false;

                }
            }
            this.picKeep.Visible = true;
            this.picUnKeep.Visible = false;
            switch (nStatus)
            {
                //受付可
                case STATE_WAIT:
                    picstatus = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040014"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\MainStatusAttention.png"), PictureBox = this.PicStatus, Enabled = true };
                    piclogoff = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040033"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picLogOff, Enabled = true };
                    picsetting = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040032"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picSetting, Enabled = false };
                    picrecept = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040003"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picRecept, Enabled = false };
                    picoperate = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picOperate, Enabled = true };
                    picleave = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040016"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picLeave, Enabled = true };
                    pickeep = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040018"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picKeep, Enabled = false };
                    picfoward = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040020"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picFoward, Enabled = false };
                    picsend = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040017"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhoneH.png"), PictureBox = this.picSend, Enabled = true };
                    piccut = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040028"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picCut, Enabled = false };
                    picphonelist = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040035"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picPhoneList, Enabled = false };
                    picphonemessage = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040036"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneMessage, Enabled = true };
                    //pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040010"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picHelp, Enabled = true };
                    picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picArrow, Enabled = true };
                    picct = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040047"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picCT, Enabled = false };
                    picmyuser = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040046"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picMyUser, Enabled = false };
                    picsky = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040055"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picSKY, Enabled = true };
                    break;
                //後処理
                case STATE_WORKTIME:
                    picstatus = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\MainStatusAgent.png"), PictureBox = this.PicStatus, Enabled = true };
                    piclogoff = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040033"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picLogOff, Enabled = true };
                    picsetting = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040032"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picSetting, Enabled = false };
                    picrecept = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040003"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgentH.png"), PictureBox = this.picRecept, Enabled = true };
                    picoperate = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picOperate, Enabled = false };
                    picleave = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040016"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picLeave, Enabled = true };
                    pickeep = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040018"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picKeep, Enabled = false };
                    picfoward = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040020"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picFoward, Enabled = false };
                    picsend = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040017"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhoneH.png"), PictureBox = this.picSend, Enabled = true };
                    piccut = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040028"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picCut, Enabled = false };
                    picphonelist = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040035"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneList, Enabled = true };
                    picphonemessage = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040036"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneMessage, Enabled = true };
                    //pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040010"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picHelp, Enabled = true };
                    picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picArrow, Enabled = true };
                    picct = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040047"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picCT, Enabled = false };
                    picmyuser = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040046"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picMyUser, Enabled = true };
                    picsky = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040055"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picSKY, Enabled = true };
                    this.notifyIcon.Icon = new Icon(Application.StartupPath + @"\Image\PhoneNormal.ico");
                    break;
                //離席中
                case STATE_SEATOFF:
                    picstatus = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040005"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\MainStatusDisable.png"), PictureBox = this.PicStatus, Enabled = true };
                    piclogoff = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040033"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picLogOff, Enabled = true };
                    picsetting = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040032"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picSetting, Enabled = false };
                    picrecept = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040003"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgentH.png"), PictureBox = this.picRecept, Enabled = true };
                    picoperate = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picOperate, Enabled = true };
                    picleave = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040016"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLeave, Enabled = false };
                    pickeep = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040018"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picKeep, Enabled = false };
                    picfoward = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040020"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picFoward, Enabled = false };
                    picsend = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040017"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhoneH.png"), PictureBox = this.picSend, Enabled = true };
                    piccut = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040028"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picCut, Enabled = false };
                    picphonelist = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040035"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneList, Enabled = true };
                    picphonemessage = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040036"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneMessage, Enabled = true };
                    // pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040010"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picHelp, Enabled = true };
                    picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picArrow, Enabled = true };
                    picct = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040047"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picCT, Enabled = false };
                    picmyuser = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040046"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picMyUser, Enabled = true };
                    picsky = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040055"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picSKY, Enabled = true };
                    break;
                //通话中
                case STATE_CONNECT:
                    picstatus = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040007"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\MainStatusPhone.png"), PictureBox = this.PicStatus, Enabled = true };
                    piclogoff = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040033"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLogOff, Enabled = false };
                    picsetting = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040032"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picSetting, Enabled = false };
                    picrecept = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040003"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picRecept, Enabled = false };
                    picoperate = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picOperate, Enabled = false };
                    picleave = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040016"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLeave, Enabled = false };
                    pickeep = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040018"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picKeep, Enabled = true };
                    picfoward = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040020"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picFoward, Enabled = false };
                    picsend = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040017"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picSend, Enabled = false };
                    piccut = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040028"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAttentionH.png"), PictureBox = this.picCut, Enabled = true };
                    picphonelist = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040035"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneList, Enabled = true };
                    picphonemessage = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040036"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneMessage, Enabled = true };
                    //pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040010"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picHelp, Enabled = true };
                    picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picArrow, Enabled = true };
                    picct = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040047"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picCT, Enabled = true };
                    picmyuser = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040046"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picMyUser, Enabled = true };
                    picsky = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040055"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picSKY, Enabled = true };
                    PlaySound(null, new IntPtr(), playSound.SND_ASYNC);
                    break;
                //保留中
                case STATE_HOLDING:
                    picstatus = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040008"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\MainStatusNotice.png"), PictureBox = this.PicStatus, Enabled = true };
                    this.picKeep.Visible = false;
                    this.picUnKeep.Visible = true;
                    piclogoff = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040033"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLogOff, Enabled = false };
                    picsetting = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040032"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picSetting, Enabled = false };
                    picrecept = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040003"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picRecept, Enabled = false };
                    picoperate = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picOperate, Enabled = false };
                    picleave = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040016"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLeave, Enabled = false };
                    pickeep = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040018"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picKeep, Enabled = true };
                    picfoward = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040020"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picFoward, Enabled = true };
                    picsend = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040017"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhoneH.png"), PictureBox = this.picSend, Enabled = true };
                    piccut = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040028"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picCut, Enabled = false };
                    picphonelist = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040035"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneList, Enabled = true };
                    picphonemessage = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040036"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneMessage, Enabled = true };
                    //pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040010"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picHelp, Enabled = true };
                    picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picArrow, Enabled = true };
                    picct = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040047"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picCT, Enabled = false };
                    picmyuser = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040046"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picMyUser, Enabled = true };
                    picunKeep = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040019"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonNotice.png"), PictureBox = this.picUnKeep, Enabled = true };
                    picsky = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040055"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picSKY, Enabled = true };
                    break;
                case STATE_OFFERING:
                    picstatus = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040006"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\MainStatusNotice.png"), PictureBox = this.PicStatus, Enabled = true };
                    piclogoff = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040033"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLogOff, Enabled = false };
                    picsetting = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040032"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picSetting, Enabled = false };
                    picrecept = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040003"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picRecept, Enabled = false };
                    picoperate = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picOperate, Enabled = false };
                    picleave = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040016"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLeave, Enabled = false };
                    pickeep = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040018"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picKeep, Enabled = true };
                    picfoward = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040020"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picFoward, Enabled = true };
                    picsend = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040017"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picSend, Enabled = false };
                    piccut = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040028"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAttentionH.png"), PictureBox = this.picCut, Enabled = true };
                    picphonelist = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040035"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneList, Enabled = true };
                    picphonemessage = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040036"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneMessage, Enabled = true };
                    //pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040010"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picHelp, Enabled = true };
                    picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picArrow, Enabled = true };
                    picct = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040047"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picCT, Enabled = false };
                    picmyuser = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040046"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picMyUser, Enabled = true };
                    picsky = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040055"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picSKY, Enabled = true };
                    break;
                case STATE_TRANOFFERING:
                    break;
                case STATE_TELEPHONE:
                case STATE_CALLING:
                case STATE_NMCALLING:
                    picstatus = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040007"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\MainStatusPhone.png"), PictureBox = this.PicStatus, Enabled = true };
                    piclogoff = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040033"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLogOff, Enabled = false };
                    picsetting = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040032"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picSetting, Enabled = false };
                    picrecept = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040003"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picRecept, Enabled = false };
                    picoperate = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040015"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picOperate, Enabled = false };
                    picleave = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040016"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picLeave, Enabled = false };
                    pickeep = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040018"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picKeep, Enabled = false };
                    picfoward = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040020"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picFoward, Enabled = false };
                    picsend = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040017"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisableH.png"), PictureBox = this.picSend, Enabled = false };
                    piccut = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040028"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAttentionH.png"), PictureBox = this.picCut, Enabled = true };
                    picphonelist = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040035"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneList, Enabled = true };
                    picphonemessage = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040036"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picPhoneMessage, Enabled = true };
                    //pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040010"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picHelp, Enabled = true };
                    picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picArrow, Enabled = true };
                    picct = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040047"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picCT, Enabled = true };
                    picmyuser = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040046"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picMyUser, Enabled = true };
                    picsky = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040055"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picSKY, Enabled = true };
                    
                    break;
            }

            PictureBoxTool.DrawInPictureBox(picstatus);
            PictureBoxTool.DrawInPictureBox(piclogoff);
            PictureBoxTool.DrawInPictureBox(picsetting);
            PictureBoxTool.DrawInPictureBox(picrecept);
            PictureBoxTool.DrawInPictureBox(picoperate);
            PictureBoxTool.DrawInPictureBox(picleave);
            PictureBoxTool.DrawInPictureBox(pickeep);
            PictureBoxTool.DrawInPictureBox(picunKeep);
            PictureBoxTool.DrawInPictureBox(picfoward);
            PictureBoxTool.DrawInPictureBox(picsend);
            PictureBoxTool.DrawInPictureBox(piccut);
            PictureBoxTool.DrawInPictureBox(picphonelist);
            PictureBoxTool.DrawInPictureBox(picphonemessage);
            //PictureBoxTool.DrawInPictureBox(pichelp);
            PictureBoxTool.DrawInPictureBox(picarrow);
            PictureBoxTool.DrawInPictureBox(picct);
            PictureBoxTool.DrawInPictureBox(picmyuser);
            PictureBoxTool.DrawInPictureBox(picsky);
            this.picHelp.Enabled = true;
        }

        private void picLogOff_Click(object sender, System.EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picLogOff_Click Started");
                CmdLogoff();
                CommonFunction.WriteLog("picLogOff_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void picRecept_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picRecept_Click Started");
                g_clickWork = 0;
                CmdBgnWait();
                CommonFunction.WriteLog("picRecept_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picOperate_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picOperate_Click Started");
                CmdBgnWorktime();
                CommonFunction.WriteLog("picOperate_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picLeave_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picLeave_Click Started");
                CmdBgnSeatoff();
                CommonFunction.WriteLog("picLeave_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picSC_Click(object sender, EventArgs e)
        {

        }

        private void picKeep_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picKeep_Click Started");
                CmdBgnHold();
                CommonFunction.WriteLog("picKeep_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


        private void picUnKeep_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picUnKeep_Click Started");
                CmdEndHold();
                CommonFunction.WriteLog("picUnKeep_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picFoward_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picFoward_Click Started");
                CmdGetList();
                CommonFunction.WriteLog("picFoward_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("btnSend_Click Started");
                CmdConnect();
                CommonFunction.WriteLog("btnSend_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picCut_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picCut_Click Started");
                CmdDisconnect();
                CommonFunction.WriteLog("picCut_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picPhoneList_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picPhoneList_Click Started");
                CmdRecordList();
                CommonFunction.WriteLog("picPhoneList_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picPhoneMessage_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picPhoneMessage_Click Started");
                string postData = "u=" + _ResProfile.AgentID + "&ln=" + Language + "&formName=agentMain&upwd=" + _ResProfile.AgentPassword;
                string url = _ResProfile.UserUrl + "agentpanel_callback.asp";
                CommonFunction.IEOpenOnURL(url, postData, 700, 600, false);
                CommonFunction.WriteLog("picPhoneMessage_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picHelp_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picHelp_Click Started");
                if (g_iHelp == 0)
                {
                    PicBoxStatus pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040024"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonNotice.png"), PictureBox = this.picHelp, Enabled = true };
                    PictureBoxTool.DrawInPictureBox(pichelp);
                }
                else if (g_iHelp == 1)
                {
                    PicBoxStatus pichelp = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040010"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonPhone.png"), PictureBox = this.picHelp, Enabled = true };
                    PictureBoxTool.DrawInPictureBox(pichelp);
                }
                CmdConference();
                CommonFunction.WriteLog("picHelp_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picCT_Click(object sender, EventArgs e)
        {

        }

        private void picMyUser_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picMyUser_Click Started");
                string postData = "u=" + _ResProfile.AgentID + "&ln=" + Language + "&formName=agentMain&upwd=" + _ResProfile.AgentPassword;
                postData += "&t=" + _ResProfile.TenantID + "&tel=" + g_vTel;
                string url = _ResProfile.UserUrl + "CustomOption1.asp";
                CommonFunction.IEOpenOnURL(url, postData, 500, 400, false);
                CommonFunction.WriteLog("picMyUser_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picArrow_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picArrow_Click Started");
                PicBoxStatus picNotice;
                this.Height = _MessageHeight;
                PicBoxStatus picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picArrow };
                if (this.picLogOff.Visible)
                    picNotice = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040031"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picNotice, Enabled = true };
                else
                    picNotice = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040031"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonDisable.png"), PictureBox = this.picNotice };
                PicBoxStatus picClose = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0020002"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picClose, Enabled = true };

                PictureBoxTool.DrawInPictureBox(picarrow);
                PictureBoxTool.DrawInPictureBox(picNotice);
                PictureBoxTool.DrawInPictureBox(picClose);
                CommonFunction.WriteLog("picArrow_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void Acx_OnMakeCallRequest()
        {
            CpfParams objArgParams = new CpfParams();
            _LpcSvr.SendEvent("OnMakeCallRequest", objArgParams.GetParams());
        }

        private void onShowMsg()
        {
            this.Height = _MessageHeight;
        }

        private void onUnShowMsg()
        {
            this.Height = _NoMessageHeight;
        }

        private void autoWait()
        {
            _AutoWait.Enabled = false;
            //add,xzg,2009/12/01,S---
            if (g_clickWork == 1)
            {
                g_clickWork = 0;
                g_isSetWatiTime = 0;
                return;
            }
            g_clickWork = 0;
            //add,xzg,2009/12/01,E---
            this.picRecept_Click(null, null);
            g_isSetWatiTime = 0;
        }

        private void picLogon_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picLogon_Click Started");
                CmdLogon();
                CommonFunction.WriteLog("picLogon_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picSKY_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picSKY_Click Started");
                string url = _ResProfile.UserUrl + "agentpanel_call.asp?tid=" + _ResProfile.TenantID + "&u=" + _ResProfile.AgentID + "&ln=" + Language;
                System.Diagnostics.Process.Start(url);
                CommonFunction.WriteLog("picSKY_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void picSend_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picSend_Click Started");
                CmdConnect();
                CommonFunction.WriteLog("picSend_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void picBox_MouseHover(object sender, EventArgs e)
        {
            if (!(sender as PictureBox).Enabled)
                this.Cursor = Cursors.No;
            else
                this.Cursor = Cursors.Hand;
        }

        private void picBox_MouseLeave(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Default;
        }

        private void picNotice_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picNotice_Click Started");
                CmdMessage();
                CommonFunction.WriteLog("picNotice_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void picClose_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("picClose_Click Started");
                this.Height = _NoMessageHeight;
                PicBoxStatus picarrow = new PicBoxStatus() { Title = _ResourceManager.GetString("AP0040054"), BackGroudImage = Image.FromFile(Application.StartupPath + @"\Image\PanelButtonAgent.png"), PictureBox = this.picArrow, Enabled = true };
                PictureBoxTool.DrawInPictureBox(picarrow);
                CommonFunction.WriteLog("picClose_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void notifyIcon_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("notifyIcon_DoubleClick Started");
                if (this.WindowState == FormWindowState.Minimized)
                {
                    this.Show();
                    this.ShowInTaskbar = true;
                    this.WindowState = FormWindowState.Normal;
                }
                else
                {
                    this.Hide();
                    this.ShowInTaskbar = true;
                    this.WindowState = FormWindowState.Minimized;
                }
                CommonFunction.WriteLog("notifyIcon_DoubleClick Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void cmbCallerList_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape)
            {
                this.cmbCallerList.Visible = false;
                this.txtTeleNo.Visible = true;
            }
        }


        private void cmbCallerList_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("cmbCallerList_SelectedIndexChanged Started");
                this.cmbCallerList.Visible = false;
                this.txtTeleNo.Visible = true;
                this.txtTeleNo.Text = this.cmbCallerList.Text;
                CommonFunction.WriteLog("cmbCallerList_SelectedIndexChanged Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void txtTeleNo_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Down)
            {
                this.cmbCallerList.Visible = true;
                this.txtTeleNo.Visible = false;
            }
        }

        private void ChangePassword_Click(object sender, EventArgs e)
        {
            frmWebPage frm = new frmWebPage();
            frm.ShowDialog();
        }

        private void ShowOrNotShow_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("ShowOrNotShow_Click Started");
                this.Visible = !this.Visible;
                CommonFunction.WriteLog("ShowOrNotShow_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void Version_Click(object sender, EventArgs e)
        {
            try
            {
                CommonFunction.WriteLog("Version_Click Started");
                frmVersion frm = new frmVersion();
                frm.ShowDialog();
                CommonFunction.WriteLog("Version_Click Ended");
            }
            catch (Exception ex)
            {
                CommonFunction.WriteLog(ex.Message);
                MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void Close_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

    }

}
